{% extends "./inc/base.html" %}
{% block content %}
                <section class="vbox">
                    <header class="header bg-light dk">
                        <p>{{meta_title}}</p>
                    </header>
                    <section class="scrollable wrapper">
                      <div class="row"><div class="col-lg-12">
                        <section class="panel panel-default">
                            <div class="panel-body">
                                <form id="ajaxForm" method="post" class="form-horizontal" action="{{action}}">
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置标识</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-4">
                                            <input type="text" class="form-control" name="name" value="{{info.name if info.name else null}}"  data-required="true" data-Remote="/admin/setup/parsley">
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 用于<code>this.config('setup.配置标识')</code>函数调用，只能使用英文且不能重复</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置标题</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-4">
                                            <input type="text" class="form-control" name="title" value="{{info.title if info.title else null}}" data-required="true">
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 用于后台显示的配置标题</span>
                                                </div>
                                        </div>
                                    </div>
                                        </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">

                                        <label class="col-sm-2 control-label">排序</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-3">
                                            <input type="text" class="form-control" name="sort" value="0">

                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 用于分组显示的顺序</span>
                                                </div>
                                        </div>
                                    </div>
                                        </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置类型</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-2">
                                            <select class="form-control " name="type">
                                                {% for index, items in config.setup.CONFIG_TYPE_LIST %}
                                                <option value="{{index}}" {% if info.type == index %} selected {% endif %}>{{items}}</option>
                                                {% endfor%}
                                            </select>
                                                    </div>
                                                    <div class="col-md-12">
                                                        <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 系统会根据不同类型解析配置值</span>
                                                    </div>
                                                </div>
                                        </div>
                                    </div>

                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置分组</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-3">
                                            <select class="form-control " name="group">
                                                <option value="0">不分组</option>
                                                {% for index, items in config.setup.CONFIG_GROUP_LIST %}
                                                <option value="{{index}}" {% if info.group == index %} selected {% endif %}>{{items}}</option>
                                                {% endfor%}
                                            </select>
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 配置分组 用于批量设置 不分组则不会显示在系统设置中</span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置值</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-5">
                                                <textarea class="form-control" name="value">{{ info.value }}</textarea>
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 配置值 </span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">配置项</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-5">
                                            <textarea class="form-control" name="extra">{{ info.extra }}</textarea>
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 如果是枚举型 需要配置该项 </span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">说明</label>
                                        <div class="col-sm-10">
                                            <div class="row">
                                                <div class="col-md-5">
                                            <textarea class="form-control" name="remark">{{ info.remark }}</textarea>
                                                </div>
                                                <div class="col-md-12">
                                                    <span class="help-block m-b-none text-muted"><i class="fa fa-info-circle text-info"></i> 配置详细说明 </span>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="line line-dashed b-b line-lg pull-in"></div>
                                    <div class="form-group form-submit">
                                        <div class="col-sm-4 col-sm-offset-2">
                                            <button class="btn btn-primary" type="submit" id="btn">确定</button>
                                            <button class="btn btn-default" onclick="javascript:history.back(-1);return false;" type="submit">返回</button>

                                        </div>
                                    </div>
                                </form>
                            </div>
                        </section>
                      </div></div>
                    </section>
                </section>

{% endblock %}

{% block script%}
<script src="/static/admin/js/parsley/parsley.min.js" type="text/javascript"></script>
<script src="/static/admin/js/parsley/parsley.extend.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function(){

        $('#ajaxForm #btn').on('click', function () {
            $('#ajaxForm').parsley().validate();
            if (true === $('#ajaxForm').parsley().isValid()) {
                _addFun();
            }
            return false;
        });

        function _addFun() {
            var AjaxURL= $('#ajaxForm').attr("action");
            var jsonData = $('#ajaxForm').serialize();
            $.ajax({
                url: AjaxURL,
                data: jsonData,
                type: "post",
                success: function (data) {
                    console.log(data)
                    if (data) {
                        //$("#myModal").modal("hide");
                        resetFrom();
                        toastr.success('添加成功!')
                        location.href = "/admin/setup/group";
                    }
                }, error: function (error) {
                    console.log(error);
                }
            });
        }
        /**
         * 重置表单
         */
        function resetFrom() {
            $('form').each(function (index) {
                $('form')[index].reset();
            });
        }

    })
</script>
{% endblock %}